package com.ruoyi.ly.controller;


import com.ruoyi.ly.domain.dto.PageProjectDTO;
import com.ruoyi.ly.domain.dto.ProjectAddDTO;
import com.ruoyi.ly.domain.dto.ProjectUpdateDTO;
import com.ruoyi.ly.domain.vo.AllProjectVO;
import com.ruoyi.ly.domain.vo.ProjectUpdateVO;
import com.ruoyi.ly.service.ProjectService;
import com.ruoyi.ly.utils.PageResult;
import com.ruoyi.ly.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@CrossOrigin
@RestController
@RequestMapping("/project")
@Slf4j
@Api(tags = "项目管理接口")
public class ProjectController {

    @Autowired
    private ProjectService projectService;


    //分页查询
    @ApiOperation("分页查询项目")
    @GetMapping("/page")
    public Result<PageResult> page(PageProjectDTO pageProjectDto) {
        log.info("分页查询：{}", pageProjectDto);
        PageResult pageResult = projectService.pageQuery(pageProjectDto);
        return Result.success(pageResult);
    }

    //添加项目
    @ApiOperation("添加项目")
    @PostMapping("/add")
    private Result insert(@RequestBody ProjectAddDTO projectAddDto) {
        log.info("添加项目：{}", projectAddDto);
        projectService.insert(projectAddDto);
        return Result.success();
    }

    //删除项目
    @ApiOperation("删除项目")
    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable("id")Integer id) {
        log.info("删除项目：{}", id);
        projectService.delete(id);
        return Result.success();
    }

    //修改项目
    @ApiOperation("修改项目")
    @PutMapping("/update")
    public Result update(@RequestBody ProjectUpdateDTO projectUpdateDto) {
        log.info("修改项目：{}", projectUpdateDto);
        projectService.update(projectUpdateDto);
        return Result.success();
    }

    //根据项目id查询项目
    @ApiOperation("根据项目id查询项目")
    @GetMapping("/selectById")
    public  Result<ProjectUpdateVO> selectById(Long id) {
        log.info("根据项目id查询项目：{}",id);
        ProjectUpdateVO projectUpdateVo = projectService.selectById(id);
        return Result.success(projectUpdateVo);
    }

//    //查询所有项目和企业
//    @ApiOperation("查询所有项目和企业")
//    @GetMapping("/selectAll")
//    public Result< List<AllProjectVO>> selectAll() {
//        log.info("查询所有项目和企业：{}");
//       List<AllProjectVO> allProjectVOList= projectService.selectAll();
//        return Result.success(allProjectVOList);
//    }

}

